Ext.define('PJ.view.unitregistrationmanagement.CloseUserListFrame', {
    extend: 'AM.default.DefaultWindowForm',
    requires: ['AM.default.DefaultDateField', 
               'AM.default.DateTime', 
               'AM.default.jsonp.DefaultSubmitJsonp',
               'PJ.view.unitregistrationmanagement.CloseUserList'
               ],
    
    modal: true,// 开启不允许点击其他组件
    frame: true,
    notEdit: true,
    width: 1255,
    height: 575,
    isSame: false,
    isEdit: null,

    initComponent: function(){
    	var me = this;
    	
    	me.items= [{
    		xtype: "fieldset",
    		layout: 'column',
            collapsible: false, //显示三角
            defaults: {
    			xtype: 'textfield',
            	labelAlign: 'right',
            	labelWidth: 65,
            	readOnly: true,
            	fieldCls: 'noBorder',
            	columnWidth: .5
            },
    		items: [{
    			xtype : 'displayfield',
            	value : '<div style="color: red;text-align:left;font-size:16px">重要提示：请认真核对以下报名人员信息，此信息将做为培训手册内容印发。</div>',
            	columnWidth: 1
    		}]
    	}, {
    		xtype: "fieldset",
    		layout: 'column',
            collapsible: false, //显示三角
            height:453,
    		items: [{
    			xtype: 'CloseUserList',
            	columnWidth: 1,
            	grid:this,
            	userIds:me.userIds,
            	deptId:me.deptId,
            	clickSource:me.clickSource,
    			auditingState:me.auditingState,
            	height:430
    		}]
    	}];
        me.buttons = [{
        	id:'affirm',
            text: '确认',
            scope: this,
            handler: this.closeTwo
        },{
            text: '返回',
            scope: this,
            handler: this.close
        }/*,{
        	text:'导出',
        	scope:this,
        	handler:this.onExportClick
        }*/];
        me.callParent(arguments);
    },
    //导出
    onExportClick: function(){
    	var store = this.win.grid.getStore();
    	var href=store.exportUrl + "?searchClassIds=" + this.classId;
    	href+="&clickSource="+this.win.clickSource;
    	
    	href = encodeURI(href);
    	var atag = Ext.get("exportResume");
    	atag.set({
    		"href": href
    	});
    	atag.dom.click();
    },
    //关闭到最外层页面
    closeTwo:function(button){
    	var me=this;
    	var store=me.down('CloseUserList').getStore();
    	if(store.data.items.length==0){
    		Ext.Msg.show({
				icon: Ext.MessageBox.ERROR,  
				title: '提示消息',  
				buttons: Ext.MessageBox.OK,  
				msg: '没有可报名人员！'  
			});
    		return;
    	}
    	var isNull=1;
    	var phoneFlag=true;
    	store.each(function(datas){
//            if (datas.data.folkCode=='') {
////            	Ext.MessageBox.alert('注意','<div style="color: red;text-align:center;">民族信息需要填写完整！</div>');
//            	Orchid.alert('消息', '民族信息需要填写完整！');
//            	isNull=2;
//            	return;
//            }
            if (datas.data.mobileTelephone!=''&&datas.data.mobileTelephone.length!=11) {
//            	Ext.MessageBox.alert('注意','<div style="color: red;text-align:center;">手机号码位数不足，请确认后重新输入！</div>');
            	Orchid.alert('消息', '手机号码位数不足，请确认后重新输入！');
            	isNull=2;
            	phoneFlag=false;
            	return;
            }
        });
    	if(phoneFlag){
    		if(me.win.up("window").reportPhone!=undefined&&me.win.up("window").reportPhone.length>0){
    			Orchid.alert('消息', '存在重复的手机号码，请检查后重新输入！');
    			isNull=2;
    			return;
    		}
    	}
    	if(isNull==1){
    		var flag=false;
    		//判断是否限制班级人数
    		if(me.classUserNum){
        		//判断是否超过限制人数限制
        		var num = me.down('CloseUserList').store.data.items.length;
    			Ext.Ajax.request({
					url: me.win.getStore().findListUserCountUrl,  
					method: 'POST',  
					async: false,
					params:{
						userCount:me.classUserNum,
						preCount:num,
						searchClassID:me.classId
					},  
					success: function(response) {
						var data=JSON.parse(response.responseText);
						if(!data.success){
							Ext.Msg.show({
								icon: Ext.MessageBox.INFO,  
								title: '提示信息',  
								buttons: Ext.MessageBox.OK,
								msg: data.msg  
							});  
						}else{
							flag=true;
						}
						return;
					}
				});
    		}else{
    			flag=true;
    		}
    		
    		if(flag){
    			Ext.Msg.confirm({
    				title: '提示',
    				msg: '您确定要为这些学员报名吗？',
    				buttons: Ext.Msg.OKCANCEL,
    				fn: function(id) {
    					if (id == 'ok') {
    						Ext.getCmp('affirm').disable();
    						Ext.Ajax.request({
    							url: me.win.getStore().selectUserSave,  
    							method: 'POST',  
    							submitEmptyText: false,  
    							jsonData: Ext.encode(Ext.pluck(store.data.items, 'data')),
    							params:{
    								searchClassID:me.classId,
    								auditingState:me.auditingState,
    								clickSource:me.clickSource,
    								searchDepId:me.deptId
    							},  
    							success: function(response) {
    								var data=JSON.parse(response.responseText);
    								Ext.Msg.show({
    									icon: Ext.MessageBox.INFO,  
    									title: '提示信息',  
    									buttons: Ext.MessageBox.OK,
    									msg: data.msg  
    								});  
    								if(data.success){
    									me.close();
    									me.win.up('window').down("ChooseUserList").store.load();
    									me.win.up('window').down("ChooseNoUserList").store.load();
    								}
    							},
    							failure: function(response) {
    								var result = Ext .decode(response.responseText);  
    								Ext.Msg.show({
    									icon: Ext.MessageBox.ERROR,  
    									title: '提示消息',  
    									buttons: Ext.MessageBox.OK,  
    									msg: result.errMsg  
    								});  
    							}  
    						});
    					}else{
    						return;
    					}
    				}
    			});
    		}
    	}else if(store.data.items.length==0)
			me.close();
    },
//    colse:function (){
//		this.win.up('window').down("ChooseNoUserList").store.load();
//		this.close;
//    },
//    closes:function(button){
//    	
//    	this.close();
//    },
    listeners: {
//    	show: function(){
//    		 
//             var loadMask = new Ext.LoadMask(this, {
//                 msg: orchid_lang.promptWindowInfo.loadingText
//             });
//             this.down("CloseUserList").loadMask = loadMask;
//             
// 			//刷新已选人员
// 			var store = this.down("CloseUserList").getStore();
// 			var newParams = {
//                 searchClassID:this.classId,
//     			clickSource:this.grid.clickSource,
//     			limit:30
//             };
//             // 4.0强制更改store参数写法
//             var params = store.proxy.extraParams;
//             Ext.apply(params, newParams);
//             // grid加载生效
//             store.isLoad = true;
//             store.load();
//         }
//	    afterrender: function(){
//			var win = this;
//			
//			var baseForm = win.down('form').getForm();
//			var classMainName = baseForm.findField('classMainName');//班级名称
//	//		var ministrieName = baseForm.findField('ministrieName');//委托部委
//			var learnTime = baseForm.findField('learnTime');//举办时间
//	
//			classMainName.setValue(win.classMainName);
//	//		ministrieName.setValue(win.ministrieName);
////			learnTime.setValue(win.beginDate + '至' + win.endDate);
//			learnTime.setValue(win.learnTime);
//		}
    }
});
